package com.ruoyi.web.controller.saleManagement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.saleManagement.saleRegisterInfo.domain.SaleRegisterInfo;
import com.ruoyi.saleManagement.saleRegisterInfo.service.ISaleRegisterInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 售后登记信息Controller
 * 
 * @author YiYuan
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/saleManagement/saleRegister")
@RequiredArgsConstructor
public class SaleRegisterInfoController extends BaseController
{
    private final ISaleRegisterInfoService saleRegisterInfoService;

    /**
     * 查询售后登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:list')")
    @GetMapping("/list")
    public TableDataInfo list(SaleRegisterInfo saleRegisterInfo)
    {
        startPage();
        List<SaleRegisterInfo> list = saleRegisterInfoService.selectSaleRegisterInfoList(saleRegisterInfo);
        return getDataTable(list);
    }

    /**
     * 导出售后登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:export')")
    @Log(title = "售后登记信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleRegisterInfo saleRegisterInfo)
    {
        List<SaleRegisterInfo> list = saleRegisterInfoService.selectSaleRegisterInfoList(saleRegisterInfo);
        ExcelUtil<SaleRegisterInfo> util = new ExcelUtil<SaleRegisterInfo>(SaleRegisterInfo.class);
        util.exportExcel(response, list, "售后登记信息数据");
    }

    /**
     * 获取售后登记信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:query')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@PathVariable("registerId") String registerId)
    {
        return success(saleRegisterInfoService.selectSaleRegisterInfoByRegisterId(registerId));
    }

    /**
     * 新增售后登记信息
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:add')")
    @Log(title = "售后登记信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleRegisterInfo saleRegisterInfo)
    {
        saleRegisterInfo.setSource("02");
        return toAjax(saleRegisterInfoService.insertSaleRegisterInfo(saleRegisterInfo));
    }

    /**
     * 修改售后登记信息
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:edit')")
    @Log(title = "售后登记信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleRegisterInfo saleRegisterInfo)
    {
        return toAjax(saleRegisterInfoService.updateSaleRegisterInfo(saleRegisterInfo));
    }

    /**
     * 删除售后登记信息
     */
    @PreAuthorize("@ss.hasPermi('saleManagement:saleRegister:remove')")
    @Log(title = "售后登记信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{registerIds}")
    public AjaxResult remove(@PathVariable String[] registerIds)
    {
        return toAjax(saleRegisterInfoService.deleteSaleRegisterInfoByRegisterIds(registerIds));
    }
}
